package java_generics.why_use_generics;

import java.util.ArrayList;
import java.util.List;

public class TypeSafety {

	public static void main(String[] args) {
		
		// Non generic version of Integer list
		List v = new ArrayList();
		Integer i;
		
		v.add(new Integer(5)); // OK
		i = (Integer)v.get(0);
		
		v.add("abc"); // NOT OK
		i = (Integer)v.get(1); // Runtime Error
		
		
		// Generic version of Integer List
		List<Integer> k = new ArrayList<>();
		k.add(new Integer(5)); // OK
		//k.add("abc"); // Compile error
		// The method add(Integer) in the type List<Integer>
		// is not applicable for the arguments (String)
	}
}
